#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
新闻预览脚本
预览新闻摘要效果
"""

from news_daily import NewsDailyGenerator
from datetime import datetime


def preview_news_summary():
    """预览新闻摘要"""
    print("=" * 60)
    print("📰 新闻摘要预览")
    print("=" * 60)
    print(f"预览时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
    print("=" * 60)
    
    # 创建新闻日报生成器
    generator = NewsDailyGenerator()
    
    # 生成报告
    print("\n🔍 正在获取新闻...")
    report = generator.generate_daily_report(max_news_items=5)
    
    if 'error' in report:
        print(f"❌ 获取新闻失败: {report['error']}")
        return
    
    news_data = report['news_data']
    ai_analysis = report['ai_analysis']
    
    print(f"✅ 成功获取 {len(news_data['items'])} 条新闻")
    print(f"📊 AI分析长度: {len(ai_analysis)} 字符")
    
    # 显示新闻摘要
    print("\n📋 新闻摘要预览:")
    print("-" * 60)
    
    for i, item in enumerate(news_data['items'], 1):
        print(f"\n{i}. {item['title']}")
        print(f"   📅 时间: {item.get('published', '未知时间')}")
        print(f"   🔗 链接: {item.get('link', '无链接')}")
        
        # 显示摘要（120字限制）
        description = item.get('description', '暂无描述')
        if len(description) > 120:
            summary = description[:120] + "..."
        else:
            summary = description
        
        print(f"   📝 摘要: {summary}")
        print(f"   📏 原长度: {len(description)} 字 → 摘要长度: {len(summary)} 字")
    
    # 显示AI分析
    print("\n🤖 AI分析预览:")
    print("-" * 60)
    print(ai_analysis)
    
    # 统计信息
    print("\n📊 内容统计:")
    print("-" * 60)
    total_original = sum(len(item.get('description', '')) for item in news_data['items'])
    total_summary = sum(min(len(item.get('description', '')), 120) for item in news_data['items'])
    
    print(f"新闻总数: {len(news_data['items'])}")
    print(f"原始内容总长度: {total_original} 字")
    print(f"摘要内容总长度: {total_summary} 字")
    print(f"压缩比例: {((total_original - total_summary) / total_original * 100):.1f}%")
    print(f"AI分析长度: {len(ai_analysis)} 字")
    print(f"总邮件长度: {total_summary + len(ai_analysis)} 字")


if __name__ == "__main__":
    preview_news_summary()
